﻿!function(a) {
    function d() {
        var b = $this.attr("id");
        a("img." + b).live("mouseenter", function() {
            var d, c = a("img." + b).length;
            for (d = 1; c >= d; d++) d <= a(this).attr("altName") ? a("img#" + b + "-" + d).attr("src", options.path + options.starOn) : a("img#" + b + "-" + d).attr("src", options.path + options.starOff);
        });
    }
    function e() {
        $this.live("mouseleave", function() {
            var e, b = a(this).attr("id"), c = a("img." + b).length, d = a("input#" + b + "-score").val();
            for (e = 1; c >= e; e++) d >= e ? a("img#" + b + "-" + e).attr("src", options.path + options.starOn) : a("img#" + b + "-" + e).attr("src", options.path + options.starOff);
        });
    }
    function f() {
        var b = $this.attr("id");
        a("img." + b).live("click", function() {
            a("input#" + b + "-score").val(a(this).attr("altName"));
        });
    }
    function g(b) {
        var e, c = $this.attr("id"), d = a("img." + c).length;
        for (a("input#" + c + "-score").val(b), e = 1; d >= e; e++) b >= e ? a("img#" + c + "-" + e).attr("src", options.path + options.starOn) : a("img#" + c + "-" + e).attr("src", options.path + options.starOff);
    }
    function h(a) {
        window.console && window.console.log && window.console.log(a);
    }
    var c, b = "../";
    null != a("#skin").attr("prePath") && (b = a("#skin").attr("prePath")), c = 500, 
    a.fn.ratingRender = function() {
        var b, d, e, f, g, h, i, j, k;
        a(this).html(" "), (null == a(this).attr("id") || "" == a(this).attr("id")) && (a(this).attr("id", "star_" + c), 
        c++), b = !1, (1 == a(this).attr("readOnly") || "true" == a(this).attr("readOnly")) && (b = !0), 
        d = 0, a(this).attr("value") && (d = Number(a(this).attr("value"))), e = "score", 
        a(this).attr("name") && (e = a(this).attr("name")), f = 5, a(this).attr("number") && (f = Number(a(this).attr("number"))), 
        g = [ uncompile(quiLanguage.rating.text1), uncompile(quiLanguage.rating.text2), uncompile(quiLanguage.rating.text3), uncompile(quiLanguage.rating.text4), uncompile(quiLanguage.rating.text5) ], 
        a(this).attr("tip") && (g = a(this).attr("tip").split(",")), h = !1, (1 == a(this).attr("starHalf") || "true" == a(this).attr("starHalf")) && (h = !0), 
        i = !1, (1 == a(this).attr("showCancel") || "true" == a(this).attr("showCancel")) && (i = !0), 
        j = "star-on.gif", k = "star-off.gif", a(this).attr("starOn") && (j = a(this).attr("starOn")), 
        a(this).attr("starOff") && (k = a(this).attr("starOff")), a(this).Rating({
            readOnly: b,
            start: d,
            scoreName: e,
            number: f,
            hintList: g,
            starHalf: h,
            showCancel: i,
            starOn: j,
            starOff: k
        }), a(this).find("img").each(function() {
            try {
                addTooltip(a(this)[0]);
            } catch (b) {}
        });
    }, a.fn.Rating = function(b) {
        var c, d, e, f, g, i, j, k, l, m, n, o, p, q, r, s;
        if (options = a.extend({}, a.fn.Rating.defaults, b), void 0 === this.attr("id")) return h("Invalid selector!"), 
        void 0;
        for ($this = a(this), options.number > 20 ? options.number = 20 : options.number < 0 && (options.number = 0), 
        "/" != options.path.substring(options.path.length - 1, options.path.length) && (options.path += "/"), 
        c = $this.attr("id"), d = options.path, e = options.cancelOff, f = options.cancelOn, 
        g = options.showHalf, i = options.starHalf, j = options.starOff, k = options.starOn, 
        l = options.onClick, m = 0, n = "", !isNaN(options.start) && options.start > 0 && (m = options.start > options.number ? options.number : options.start), 
        o = 1; o <= options.number; o++) n = options.number <= options.hintList.length && null !== options.hintList[o - 1] ? options.hintList[o - 1] : o, 
        starFile = m >= o ? k : j, $this.append('<img width="16" id="' + c + "-" + o + '" src="' + d + starFile + '" altName="' + o + '" title="' + n + '" class="' + c + '"/>').append(o < options.number ? "&nbsp;" : "");
        return $this.append('<input id="' + c + '-score" type="hidden" name="' + options.scoreName + '"/>'), 
        a("#" + c + "-score").val(m), g && (p = a("input#" + c + "-score").val(), q = Math.ceil(p), 
        r = (q - p).toFixed(1), r >= .3 && .7 >= r ? (q -= .5, a("img#" + c + "-" + Math.ceil(q)).attr("src", d + i)) : r >= .8 ? q-- : a("img#" + c + "-" + q).attr("src", d + k)), 
        options.readOnly ? $this.css("cursor", "default") : (options.showCancel ? (s = '<img width="16" src="' + d + options.cancelOff + '" altName="x" title="' + options.cancelHint + '" class="button-cancel"/>', 
        "left" == options.cancelPlace ? $this.prepend(s + "&nbsp;") : $this.append("&nbsp;").append(s), 
        $this.css("width", 25 * options.number + 25), a("#" + c + " img.button-cancel").live("mouseenter", function() {
            a(this).attr("src", d + f), a("img." + c).attr("src", d + j);
        }).live("mouseleave", function() {
            a(this).attr("src", d + e), a("img." + c).trigger("mouseout");
        }).live("click", function() {
            a("input#" + c + "-score").val(0), l && l(0);
        })) : $this.css("width", 25 * options.number), a("img." + c).live("mouseenter", function() {
            var e, b = a("img." + c).length;
            for (e = 1; b >= e; e++) e <= a(this).attr("altName") ? a("img#" + c + "-" + e).attr("src", d + k) : a("img#" + c + "-" + e).attr("src", d + j);
        }).live("click", function() {
            a("input#" + c + "-score").val(a(this).attr("altName")), l && l(a(this).attr("altName"));
        }).live("mouseleave", function() {
            var h, l, m, b = c, e = a("img." + b).length, f = a("input#" + b + "-score").val();
            for (h = 1; e >= h; h++) f >= h ? a("img#" + b + "-" + h).attr("src", d + k) : a("img#" + b + "-" + h).attr("src", d + j);
            g && (f = a("input#" + b + "-score").val(), l = Math.ceil(f), m = (l - f).toFixed(1), 
            m >= .3 && .7 >= m ? (l -= .5, a("img#" + b + "-" + Math.ceil(l)).attr("src", d + i)) : m >= .8 ? l-- : a("img#" + b + "-" + l).attr("src", d + k));
        }).css("cursor", "pointer")), $this;
    }, a.fn.Rating.defaults = {
        cancelHint: uncompile(quiLanguage.rating.cancelHint),
        cancelOff: "cancel-off.gif",
        cancelOn: "cancel-on.gif",
        cancelPlace: "left",
        hintList: [ uncompile(quiLanguage.rating.text1), uncompile(quiLanguage.rating.text2), uncompile(quiLanguage.rating.text3), uncompile(quiLanguage.rating.text4), uncompile(quiLanguage.rating.text5) ],
        number: 5,
        path: b + "libs/images/star/",
        readOnly: !1,
        scoreName: "score",
        showCancel: !1,
        showHalf: !1,
        starHalf: "star-half.gif",
        start: 0,
        starOff: "star-off.gif",
        starOn: "star-on.gif"
    }, a.fn.Rating.readOnly = function(b) {
        return b ? (a("img." + $this.attr("id")).die(), $this.css("cursor", "default").die()) : (d(), 
        e(), f(), $this.css("cursor", "pointer")), a.fn.Rating;
    }, a.fn.Rating.start = function(b) {
        return g(b), a.fn.Rating;
    }, a.fn.Rating.click = function(b) {
        var c = b >= options.number ? options.number : b;
        return g(c), options.onClick ? options.onClick(c) : h('You should add the "onClick: function() {}" option.'), 
        a.fn.Rating;
    };
}(jQuery);